
package org.example.baseinfo.controller;

import jakarta.annotation.Resource;
import org.example.baseinfo.api.SchoolApi;
import org.example.baseinfo.common.page.HxPage;
import org.example.baseinfo.common.page.HxPageRequest;
import org.example.baseinfo.common.utils.MdcUtil;
import org.example.baseinfo.common.vo.BaseResponse;
import org.example.baseinfo.pojo.vo.school.*;
import org.example.baseinfo.service.ISchoolService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
@RequestMapping("/school")
public class SchoolController implements SchoolApi {

    @Resource
    private ISchoolService organizationService;

    @Override
    @ApiOperation(value = "新增学校")
    @PostMapping(value = "/save")
    public BaseResponse<String> save(@RequestBody @Validated SaveSchoolReqVO param) {
        MdcUtil.setCallerUserMethod(param.getChannelCode(), "", "保存学校");
        return BaseResponse.success(organizationService.save(param));
    }

    @Override
    @ApiOperation(value = "修改学校")
    @PostMapping(value = "/update")
    public BaseResponse<String> update(@RequestBody @Validated UpdateSchoolReqVO param) throws Exception {
        MdcUtil.setCallerUserMethod(param.getChannelCode(), "", "更新学校");
        organizationService.update(param);
        return BaseResponse.success();
    }

    @Override
    @ApiOperation(value = "学校详情查询")
    @PostMapping(value = "/query")
    public BaseResponse<SchoolVO> query(@RequestBody @Validated QuerySchoolReqVO param) {
        MdcUtil.setCallerUserMethod(param.getChannelCode(), "", "查询学校");
        return BaseResponse.success(organizationService.query(param));
    }

    @Override
    @ApiOperation(value = "查询学校列表", notes = "无条件则全部查询")
    @PostMapping(value = "/list")
    public BaseResponse<List<SchoolVO>> queryList(@RequestBody @Validated QuerySchoolListReqVO param) {
        MdcUtil.setCallerUserMethod(param.getChannelCode(), "", "查询学校列表");
        return BaseResponse.success(organizationService.list(param));
    }

    @Override
    @ApiOperation(value = "分页查询学校列表", notes = "无条件则全部查询")
    @PostMapping(value = "/page")
    public BaseResponse<HxPage<SchoolVO>> queryPage(
            @RequestBody @Validated HxPageRequest<QuerySchoolListReqVO> pageRequest) {
        MdcUtil.setCallerUserMethod(pageRequest.getQuery().getChannelCode(), "", "分页查询学校列表");
        return BaseResponse.success(organizationService.page(pageRequest));
    }


    @RequestMapping(value = "/synOrgan", method = RequestMethod.GET)
    @ApiOperation(value = "mp同步", httpMethod = "GET", notes = "mp同步")
    public void synOrgan() {
        organizationService.syn();
    }
}
